home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zht1.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.5 KB  |  152 lines

  1. /* Copyright (C) 1994, 1997, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zht1.c,v 1.2 2000/09/19 19:00:54 lpd Exp $ */
  20. /* setcolorscreen operator */
  21. #include "ghost.h"
  22. #include "memory_.h"
  23. #include "oper.h"
  24. #include "estack.h"
  25. #include "gsstruct.h"        /* must precede igstate.h, */
  26.                     /* because of #ifdef in gsht.h */
  27. #include "ialloc.h"
  28. #include "igstate.h"
  29. #include "gsmatrix.h"
  30. #include "gxdevice.h"        /* for gzht.h */
  31. #include "gzht.h"
  32. #include "gsstate.h"
  33. #include "iht.h"
  34. #include "store.h"
  35.  
  36. /* Dummy spot function */
  37. private float
  38. spot_dummy(floatp x, floatp y)
  39. {
  40.     return (x + y) / 2;
  41. }
  42.  
  43. /* <red_freq> ... <gray_proc> setcolorscreen - */
  44. private int setcolorscreen_finish(P1(i_ctx_t *));
  45. private int setcolorscreen_cleanup(P1(i_ctx_t *));
  46. private int
  47. zsetcolorscreen(i_ctx_t *i_ctx_p)
  48. {
  49.     os_ptr op = osp;
  50.     gs_colorscreen_halftone cscreen;
  51.     ref sprocs[4];
  52.     gs_halftone *pht;
  53.     gx_device_halftone *pdht;
  54.     int i;
  55.     int code = 0;
  56.     int space = 0;
  57.     gs_memory_t *mem;
  58.  
  59.     for (i = 0; i < 4; i++) {
  60.     os_ptr op1 = op - 9 + i * 3;
  61.     int code = zscreen_params(op1, &cscreen.screens.indexed[i]);
  62.  
  63.     if (code < 0)
  64.         return code;
  65.     cscreen.screens.indexed[i].spot_function = spot_dummy;
  66.     sprocs[i] = *op1;
  67.     space = max(space, r_space_index(op1));
  68.     }
  69.     mem = (gs_memory_t *)idmemory->spaces_indexed[space];
  70.     check_estack(8);        /* for sampling screens */
  71.     rc_alloc_struct_0(pht, gs_halftone, &st_halftone,
  72.               mem, pht = 0, "setcolorscreen(halftone)");
  73.     rc_alloc_struct_0(pdht, gx_device_halftone, &st_device_halftone,
  74.               mem, pdht = 0, "setcolorscreen(device halftone)");
  75.     if (pht == 0 || pdht == 0)
  76.     code = gs_note_error(e_VMerror);
  77.     else {
  78.     pht->type = ht_type_colorscreen;
  79.     pht->params.colorscreen = cscreen;
  80.     code = gs_sethalftone_prepare(igs, pht, pdht);
  81.     }
  82.     if (code >= 0) {        /* Schedule the sampling of the screens. */
  83.     es_ptr esp0 = esp;    /* for backing out */
  84.  
  85.     esp += 8;
  86.     make_mark_estack(esp - 7, es_other, setcolorscreen_cleanup);
  87.     memcpy(esp - 6, sprocs, sizeof(ref) * 4);    /* procs */
  88.     make_istruct(esp - 2, 0, pht);
  89.     make_istruct(esp - 1, 0, pdht);
  90.     make_op_estack(esp, setcolorscreen_finish);
  91.     for (i = 0; i < 4; i++) {
  92.         /* Shuffle the indices to correspond to */
  93.         /* the component order. */
  94.         code = zscreen_enum_init(i_ctx_p,
  95.                      &pdht->components[(i + 1) & 3].corder,
  96.                 &pht->params.colorscreen.screens.indexed[i],
  97.                      &sprocs[i], 0, 0, mem);
  98.         if (code < 0) {
  99.         esp = esp0;
  100.         break;
  101.         }
  102.     }
  103.     }
  104.     if (code < 0) {
  105.     gs_free_object(mem, pdht, "setcolorscreen(device halftone)");
  106.     gs_free_object(mem, pht, "setcolorscreen(halftone)");
  107.     return code;
  108.     }
  109.     pop(12);
  110.     return o_push_estack;
  111. }
  112. /* Install the color screen after sampling. */
  113. private int
  114. setcolorscreen_finish(i_ctx_t *i_ctx_p)
  115. {
  116.     gx_device_halftone *pdht = r_ptr(esp, gx_device_halftone);
  117.     int code;
  118.  
  119.     pdht->order = pdht->components[0].corder;
  120.     code = gx_ht_install(igs, r_ptr(esp - 1, gs_halftone), pdht);
  121.     if (code < 0)
  122.     return code;
  123.     memcpy(istate->screen_procs.indexed, esp - 5, sizeof(ref) * 4);
  124.     make_null(&istate->halftone);
  125.     esp -= 7;
  126.     setcolorscreen_cleanup(i_ctx_p);
  127.     return o_pop_estack;
  128. }
  129. /* Clean up after installing the color screen. */
  130. private int
  131. setcolorscreen_cleanup(i_ctx_t *i_ctx_p)
  132. {
  133.     gs_halftone *pht = r_ptr(esp + 6, gs_halftone);
  134.     gx_device_halftone *pdht = r_ptr(esp + 7, gx_device_halftone);
  135.  
  136.     gs_free_object(pdht->rc.memory, pdht,
  137.            "setcolorscreen_cleanup(device halftone)");
  138.     gs_free_object(pht->rc.memory, pht,
  139.            "setcolorscreen_cleanup(halftone)");
  140.     return 0;
  141. }
  142.  
  143. /* ------ Initialization procedure ------ */
  144.  
  145. const op_def zht1_op_defs[] =
  146. {
  147.     {"<setcolorscreen", zsetcolorscreen},
  148.         /* Internal operators */
  149.     {"0%setcolorscreen_finish", setcolorscreen_finish},
  150.     op_def_end(0)
  151. };
  152.